<?php
include 'includes/application_top.inc';
include 'includes/paginate.php';
include 'auth.php';

//$_REQUEST['long_url']="http://promotepassion.com";
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Easy Living - Responsive Real Estate Template">
<meta name="keywords" content="Themes, real estate, responsive, themeforest, Templates">
<meta name="author" content="Rype Pixel [Chris Gipple]">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome Listing grid Reports</title>
<!-- html5 support in IE8 and later -->
<script src="../../html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<!-- CSS file links -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/styles.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/responsive.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<!-- Start Header -->
<?php include 'includes/header.php';?>
<!-- End Header -->
<!-- start subheader -->
<p>&nbsp;</p>
<!-- start recent properties -->
<section class="properties">
    <div class="container">
    	<?php include 'includes/left.php';?>    
        <div class="row">
            <div class="col-sm-6">
                <div class="propertyItem">
               <table border="1" class="propertyDetails">
               	<tr><td colspan="5"><div id="containertrafficlink" style="min-width: 310px; height: 300px; margin: 0 auto"></div></td></tr>
               	<tr><td colspan="5">&nbsp;</td></tr>
               	
               	<tr><td><div id="containertoplinks" style="min-width: 225px; max-width: 300px; height: 400px; margin: 0 auto"></div>
</td><td>&nbsp;</td><td><div id="containertophandset" style="min-width: 225px; max-width: 300px; height: 400px; margin: 0 auto"></td><td>&nbsp;</td><td><div id="container" style="min-width: 450px; height: 400px; margin: 0 auto"></td></tr>
               	<tr><td colspan="5">Unique User Day wise Current Month</td></tr>
               </table>               
                        		            
                </div>
            </div>
        </div><!-- end row -->
    </div><!-- end container -->
</section>
<!-- end recent properties -->
<?php
		$sql ="SELECT 	shorturl_code, COUNT(*) AS `user_count`  from track_url where `datetime` >= DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY shorturl_code  ORDER BY t_id DESC LIMIT 0,20";
	   $msReslut =mysql_query($sql);	
	   $rcounts = mysql_num_rows($msReslut);	
	 
                    $x=1;
					$getlinkname = "";
					$getlinkhit = "";
					while($r = mysql_fetch_array($msReslut)) {
						$row[0] = $r[0];
						$row[1] = $r[1];
						//  $daym = $rcount-1;
					
						 
						$comma =",";	
						 
//						echo "['".$row[0]."', ".$row[1]."]".$comma;
							$getlinkname .= "'".$row[0]."'".$comma;
							$getlinkhit .= $row[1].$comma;
						  
						//if($rcount!="")
					$x++;}
					
				$getlinknames = rtrim($getlinkname,',');
				$getlinkhits = 	rtrim($getlinkhit,',');
 
 
 $sqls ="SELECT useragent, COUNT(*) AS `user_count`  from track_url where `datetime` >= DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY useragent  ORDER BY t_id DESC  LIMIT 0,20";
	  $query  = mysql_query($sqls);
	 $numrow = mysql_num_rows($query);
	 
	                 $z=1;
					$getagentname = "";
					$getagenthit = "";
					while($r = mysql_fetch_array($query)) {
						$row[0] = $r[0];
						$row[1] = $r[1];
						//  $daym = $rcount-1;
					
						 
						$comma =",";	
						 
//						echo "['".$row[0]."', ".$row[1]."]".$comma;
                          //echo $browser = implode("",$row[0]);
                           
						    $browser = explode(" ", $row[0]);
						    @$browsertext = $browser[0].''.$browser[1];
							$getagentname .= "'".$browsertext."'".$comma;
							$getagenthit .= $row[1].$comma;
						  
						//if($rcount!="")
					$z++;}
					
					
			  		$getagentnames = rtrim($getagentname,',');
			 
			     	$getagenthits = 	rtrim($getagenthit,',');
				 
				  
		            ?> 
<div class="bottomBar">
    <div class="container">
        <p>&nbsp;</p>
    </div>
</div>

 <?php 
                $var = date('H');
			   //echo "**";
			    $pastHours = 24-$var;
			       $ar=array();        
				    for ($p=24;$p>$var; $p--)
					{
						 $ar[]=$p;
					}  
					$arrt = array_reverse($ar);
				    $aarr=array();
					for($j=1;$j<=$var; $j++)
					{
						$aarr[]= $j;
					} 
				 $hoursList= array_merge ($arrt,$aarr);
				// echo "<br>";
				 // print_r($hoursList);
				 $houmklist="";
				 for($y=0;$y<24;$y++)
				 {
				 	 
						$comma =",";	
						 
				   $houmklist .="'".$hoursList[$y]."'".$comma;	
				 }
				 // echo $houmklist;
				  			   	 	$houmklist = rtrim($houmklist,',');
				  
			   ?>      
<!-- JavaScript file links -->
<script src="js/jquery.js"></script> 		<!-- Jquery -->
<script src="js/bootstrap.min.js"></script>  <!-- bootstrap 3.0 -->
<script src="js/respond.js"></script>
 <script language="javascript">
//frm is the form element
function checkForm(theForm){
 if (
	theForm.msisdndisplay.checked == false &&
	theForm.useragentdisplay.checked == false &&
	theForm.osdisplay.checked == false &&
	theForm.shorturldisplay.checked == false &&
	theForm.longurldisplay.checked == false) 
	{
		alert ('You didn\'t choose any of the checkboxes!');
		return false;
	} else { 	
		return true;
	}
}

</script>
		<?php
		$select =  "SELECT os, COUNT(*) AS `user_count` from track_url where `datetime` >= DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY os ORDER BY t_id DESC";
        $result = mysql_query($select);
        $rows = array();
        $rcount = mysql_num_rows($result);
		?>
		<script type="text/javascript">
$(function () {
    var chart;
    
    $(document).ready(function () {
    	
    	// Build the chart
        $('#container').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            title: {
                text: 'OS Wise Traffic'
            },
            tooltip: {
        	    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: false
                    },
                    showInLegend: true
                }
            },
            series: [{
                type: 'pie',
                name: 'OS share',
                data: [
                    <?php
		             $y=1;
					while($r = mysql_fetch_array($result)) {
						$row[0] = $r[0];
						$row[1] = $r[1];
						//array_push($rows,$row);
						//echo $row[0].":".$row[1];
						if($y<$rcount)
						{
						$comma =",";	
						}
						echo "['".$row[0]."', ".$row[1]."]".$comma;
						//if($rcount!="")
					$y++;}
		
		            ?>
                ]
            }]
        });
    });
    
});
		</script>
		 <script type="text/javascript">
  
    $(function () {
        $('#containertoplinks').highcharts({
            chart: {
                type: 'bar'
            },
            title: {
                text: 'Top  20 links'
            },
            xAxis: {
               // categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
                    categories: [<?php echo trim($getlinknames);  ?>]
            },
            yAxis: {
                min: 0,
                title: {
                    text: ''
                }
            },
            legend: {
                reversed: true
            },
            plotOptions: {
                series: {
                    stacking: 'normal'
                }
            },
                series: [{
                name: 'Shortlinks',
    //            data: [5, 3, 4, 7, 2]
                 data: [<?php echo trim($getlinkhits); ?>]
            }]
        });
    });
		</script>
		
		<script type="text/javascript">
 
    
    $(function () {
        $('#containertophandset').highcharts({
            chart: {
                type: 'bar'
            },
            title: {
                text: 'Top  20 Browser'
            },
            xAxis: {
               // categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
                   categories: [<?php echo $getagentnames;?>]
            },
            yAxis: {
                min: 0,
                title: {
                    text: ''
                }
            },
            legend: {
                reversed: true
            },
            plotOptions: {
                series: {
                    stacking: 'normal'
                }
            },
                series: [{
                name: 'Browser',
    //            data: [5, 3, 4, 7, 2]
                 data: [<?php echo $getagenthits;?>]   
            }]
        });
    });
    
		</script>

		


<script type="text/javascript">
$(function () {
        $('#containertrafficlink').highcharts({
            chart: {
                type: 'line'
            },
            title: {
                text: 'Top 10 Link Wise Traffic'
            },
            subtitle: {
                text: ''
            },
            xAxis: {
              //  categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
               categories: [<?php echo $houmklist;?>]
            },
            yAxis: {
                title: {
                    text: ''
                }
            },
            plotOptions: {
                line: {
                    dataLabels: {
                       // enabled: true
					    enabled: false
                    },
//                    enableMouseTracking: false
                    enableMouseTracking: true

                }
            },
            series: [{
                name: 'Tokyo',
                data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6,7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
            }, {
                name: 'London',
                data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8,3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
            }
            ]
        });
    });
		</script>
		<?php
		//$top10="";
   $querytop10 = "SELECT 	shorturl_code,COUNT(*) AS `user_count`  from track_url where `datetime` >= DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY shorturl_code  ORDER BY user_count DESC LIMIT 0,10";		
 $resulttop10 = mysql_query($querytop10);
 $numcount = mysql_num_rows($resulttop10);	
 $n=1;	
 $arry = array();
 $arry1 = array();
 $names=array();
 $data=array();
 
  $arrpos=array();
	  $arrdos=array();
	 $urlhit1 =array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
	 $urlhit2 =array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
	 $urlhit3 =array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
	 $urlhit4 =array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
	 $urlhit5 =array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
	 $urlhit6 =array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
	 $urlhit7 =array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
	 $urlhit8 =array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
	 $urlhit9 =array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
	 $urlhit10 =array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
	 $yo=1;
	 while($rowtop10 = mysql_fetch_array($resulttop10))
	 {
// 	$top10 .= "'".$rowtop10['shorturl_code']."'".',';
    $top10 = $rowtop10['shorturl_code'];
     $sqlQuery = "SELECT shorturl_code,long_url,datetime, date(datetime), HOUR(datetime) AS Hour, COUNT(*) AS `urlcount` FROM track_url WHERE shorturl_code='".$top10."' AND `datetime` >= DATE_SUB(CURDATE(), INTERVAL 1 DAY) OR datetime IS NULL  GROUP by Hour ORDER BY Hour DESC";
//echo "<br>";
	  $query= mysql_query($sqlQuery);	
	  $arry[]="a".$n;
	  while($row = mysql_fetch_array($query))
	   { //$num="";
	//   $arry[]=$row['Hour']."**". $row['urlcount']."**".$row['shorturl_code']."<br>";	
	  $name= $row['shorturl_code'];
	  
	    $names[]= $name;
          $data[]=$row['Hour']."-".$row['urlcount']."-".$name;
	  
		  if("29Zynn"==$name)
		  {
		  	echo $row['Hour']."-".$row['urlcount']."-".$name;
		  }
		  
		  
echo $yo; echo "---------<br>";	  
	        //echo $hoursList[$i]."<br>";
		   /* for($i=0;$i<24;$i++)
			   {
				   	if($hoursList[$i]==$row['Hour'])
					{
					$num .= "'".$row['urlcount']."', ";
					}
                  else                  
					{
					$num .= "'0',";
					}
                  
			   }
			   echo $num;*/
		 // echo "<hr>";
	  }
	 
//	  echo "<hr>";
 $yo ++;
$n++; }

/*$arrsho = array();
	$querytopsh = "SELECT shorturl_code as shorturl, COUNT(*) AS `user_count`  from track_url where `datetime` >= DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY shorturl_code  ORDER BY user_count DESC LIMIT 0,10";
	$querygetprocess = mysql_query($querytopsh);
	while($myrows = mysql_fetch_row($querygetprocess))
	{
		echo $myrows['shorturl'];
	}	
print_r($arrsho);*/
// $test = getshorturlcount();
 //print_r($test);
	/*  echo "<pre>";
 print_r($data);
	  $countss= count($data);
	  //echo $numcount."-++++++++++++++";
	
	// print_r($urlhit1);
	
 
	 for($i=1;$i<$countss+1;$i++)
	{
		$exp = explode('-',$data[$i]);
		//echo $arry[$i];
		$pos = $exp[0];	
		 	 		 //print_r($exp);
	 		 if($names[$i]==$exp[2])
			 {$o=1;
		         // $exp[0]."*".$exp[1]."*".$names[$i];
			      $pos = $exp[0];			 
			      $urlhit1[$pos]=$exp[1];
					echo $o."===========";
					// $dataprocess ="\$urlhit".$i[$pos];
					//echo $arrdos[$pos] =$exp[1];
			 }$o++;
			 
		
    } */
			
			
// print_r($urlhit1);		

//print_r($names);	   
/*echo "<hr><hr><hr>";
print_r($urlhit1);

print_r($arrpos);

$original = array( 'a','b','c','d','e' );
$inserted = array( 'x' );

$artest = array_splice( $original, 3, 0, $inserted ); // splice in at position 3
echo "<pre>";
//print_r($urlhit1);


$base = array("orange", "banana", "apple", "raspberry");
$replacements = array(0 => "pineapple", 4 => "cherry");
$replacements2 = array(4 => "grape");

//$basket = array_replace($base, $replacements, $replacements2);
$basket = array_replace($base, $replacements2);
*/
//print_r($baskets);
// $original is now a b c x d e			   
			   
			   
	
// $top10;
//echo $top10url  = rtrim($top10,',');
//"SELECT shorturl_code,long_url,datetime, date(datetime), HOUR(datetime) AS Hour, COUNT(*) AS `urlcount` FROM track_url WHERE shorturl_code='29Zynn' AND `datetime` >= DATE_SUB(CURDATE(), INTERVAL 1 DAY) OR datetime IS NULL  GROUP by Hour ORDER BY Hour DESC";
?>
 
        <script src="<?php echo ROOTURL;?>js/highcharts.js"></script>
        <script src="<?php echo ROOTURL;?>js/modules/exporting.js"></script>


</body>
</html>